﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using System.Web;

namespace WorkOrders.Data
{
    class WebStrategy : ISessionStrategy
    {
        private const string _currentSessionKey = "nhibernate.current_session";

        public ISession FindSession()
        {
            HttpContext context = HttpContext.Current;
            return context != null ? context.Items[_currentSessionKey] as ISession : null;
        }

        public void AddSession(ISession session)
        {
            HttpContext context = HttpContext.Current;
            if (context != null)
                context.Items[_currentSessionKey] = session;
        }
        
        public void RemoveSession()
        {
            HttpContext context = HttpContext.Current;
            if (context != null)
                context.Items.Remove(_currentSessionKey);
        }
    }
}